# -*- coding: utf-8 -*-

from PySide.QtGui import *
from PySide.QtCore import *
import sys

QTextCodec.setCodecForTr(QTextCodec.codecForName("utf8"))

class InputDialog(QDialog):
    def __init__(self,parent=None):
        super(InputDialog, self).__init__(parent)

        nameLabel=QLabel(self.tr("姓名"))
        sexLabel = QLabel(self.tr("性别"))
        ageLabel = QLabel(self.tr("年龄"))

        self.nameValueLabel = QLabel("Zhang")
        self.nameValueLabel.setFrameStyle(QFrame.Panel | QFrame.Sunken)
        self.sexValueLabel = QLabel(self.tr("男"))

        nameButton = QPushButton("...")
        sexButton = QPushButton("...")
        ageButton = QPushButton("...")
        statureButton = QPushButton("...")

        self.connect(nameButton,SIGNAL("clicked()"),self.slotName)
        self.connect(sexButton,SIGNAL("clicked()"),self.slotSex)

        layout = QGridLayout()
        layout.addWidget(nameLabel,0,0)
        layout.addWidget(self.nameValueLabel,0,1)
        layout.addWidget(nameButton,0,2)

        layout.addWidget(sexLabel,1,0)
        layout.addWidget(self.sexValueLabel,1,1)
        layout.addWidget(sexButton,1,2)

        self.setLayout(layout)

    def slotName(self):
        name,ok=QInputDialog.getText(self,self.tr("用户名"),self.tr("请输入新的名字"),
                                     QLineEdit.Normal,self.nameValueLabel.text())
        if ok and (name != None or name !=""):
            self.nameValueLabel.setText(name)

    def slotSex(self):
        list=[self.tr("男"),self.tr("女")]
        sex,ok=QInputDialog.getItem(self,self.tr("性别"),self.tr("请选择性别"),list)

        if ok:
            self.sexValueLabel.setText(sex)

if __name__ == "__main__":
    app = QApplication(sys.argv)
    inputDialog = InputDialog()
    inputDialog.show()
    sys.exit(app.exec_())